
var V=new Vue({
    el:'#main',
    data:()=>({
        datalist:[],
        page:1,
        pageSize:10,
        listStatus:9,
        batch:[],
        cateList:[],
        allche:[]
        // id:''
    }),
    methods:{
        allsel(event){
            if($(event.target).prop('checked')){
                $(event.target).parents('table').find('input').prop('checked',true)
                this.batch=this.allche
            }else{
                $(event.target).parents('table').find('input').prop('checked',false)
                this.batch=[]
            }
        },
        onesel(did){
            if(this.batch.indexOf(did)==-1){
                this.batch.push(did)
            }else{
                this.batch.splice(this.batch.indexOf(did),1)
            }
            var isall=true
            $('td input').each(function() {
                if(!$(this).prop('checked')){
                    isall=false
                }
            })
            $('th input').prop('checked',isall)
        },
        requestSearch(){
            this.getdata()
        },
        getdata(){  //获取数据方法
            this.batch=[]
            $('table input').prop('checked',false)
            var data={
                searchText:$('#name').val(),
                // cateSelect:$('.cateSelect').val(),
                cate_id:$('.form-control').val(),
                listStatus:this.listStatus,
                page:this.page,
                limit:2
            }
            $.ajax({
                url:'/admin/product/productlist',
                type:'post',
                data,
                success:(data)=>{
                    data = JSON.parse(data)
                    this.datalist = data.productList
                    this.cateList = data.cateData
                    if(data.size / this.pageSize>1){
                        $('#pagination').show()
                        this.Resetnav(data.page-0,data.size)
                    }else{
                        $('#pagination').hide()
                    }
                    this.allche=this.datalist.map((element)=>{
                        return element.id
                    })
                }
            })
        },
        Resetnav(pageCurrent, pageSum) {
            //数据总条数
            var myPageCount = pageSum;
            //一页显示多少条
            var myPageSize = this.pageSize;
            //总页数
            var countindex = myPageCount % myPageSize > 0 ? (myPageCount / myPageSize) + 1 : (myPageCount / myPageSize);
            $.jqPaginator('#pagination', {
                totalPages: parseInt(countindex),
                //最多显示多少页
                visiblePages: 5,
                //默认显示第几页
                currentPage: pageCurrent,
                first: '<li class="first"><a href="javascript:;">'+langcon.page_home+'</a></li>',
                prev: '<li class="prev"><a href="javascript:;"><i class="arrow arrow2"></i>'+langcon.previous_page+'</a></li>',
                next: '<li class="next"><a href="javascript:;">'+langcon.next_page+'<i class="arrow arrow3"></i></a></li>',
                last: '<li class="last"><a href="javascript:;">'+langcon.last_page+'</a></li>',
                page: '<li class="page"><a href="javascript:;">{{page}}</a></li>',
                all:'<li class="page"><a href="javascript:;">'+parseInt(countindex)+' / '+this.page+'PG , '+this.pageSize+' /PG</a></li>',
                onPageChange:(num, type)=>{
                    if (type == "change") {
                        this.page=num
                    }
                }
            });
        },
        listStatusFun(status){
            this.listStatus = status
            this.page = 1
            this.getdata()
        },
        /* 产品配件 */
        itemChangeStatus(id,status){
            $.ajax({
                url:'/admin/product/itemChangeStatus',
                data: {id:id,status:status},
                type:'post',
                success:(data)=>{          
                    data = JSON.parse(data)
                    change_mes_type('.alert',data.status)
                    if(data.status==1){
                        $('.alert').show()
                        $('.alert p').html('*'+data.msg+'<br>')
                        this.getdata()
                    }else{
                        $('.alert').show()
                        $('.alert p').html('*'+data.msg+'<br>')
                    }
                }
            })
        }  ,
        requestStatus(id,requestfun,value,url){
            $.ajax({
                url:'/admin/product/'+url,
                type:'post',
                data:{
                    id:id,
                    table:'pro',
                    value:value,
                    fun:requestfun
                },
                success:(data)=>{
                    data = JSON.parse(data)
                    change_mes_type('.alert',data.status)
                    if(data.status==1){
                        $('.alert').show()
                        $('.alert p').html('*'+data.msg+'<br>')
                        this.getdata()
                    }else{
                        $('.alert').show()
                        $('.alert p').html('*'+data.msg+'<br>')
                    }
                }
            })
        },
        batchfun(value,fun,url){
            if(this.batch.length){
                var data={
                        id:this.batch,
                        table:'pro',
                        value:value,
                        fun:fun,
                    }
                $.ajax({
                    url:'/admin/product/'+url,
                    type:'post',
                    data,
                    success:(data)=>{
                        data = JSON.parse(data)
                        change_mes_type('.alert',data.status)
                        if(data.status!=1){
                            $('.alert').show()
                            $('.alert p').html('*'+data.msg+'<br>')
                            this.getdata()
                        }else{
                            $('.alert').show()
                            $('.alert p').html('*'+data.msg+'<br>')
                        }
                    }
                })
            }else{
                change_mes_type('.alert',0)
                $('.alert').show()
                $('.alert p').html('*'+this.$refs.waner.value+'<br>')
            }
        }
    },
    mounted(){
        this.getdata()
        $('#prosCopy').on('hidden.bs.modal',(e)=>{
        this.getdata()
        })
        
    },
    watch:{
        page:function(){
          this.getdata()  
        }
    }
})
$("#prosCopy").on("hidden.bs.modal", function () {
    $(this).removeData("bs.modal");
    $(".modal-content").children().remove();
});